package com.studor.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.studor.common.Result;
import com.studor.entity.Room;
import com.studor.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/room")
public class RoomController {
    
    @Autowired
    private RoomService roomService;
    
    @GetMapping("/list")
    @SaCheckLogin
    public Result<List<Room>> list() {
        List<Room> rooms = roomService.list();
        return Result.success(rooms);
    }
    
    @GetMapping("/available")
    @SaCheckLogin
    public Result<List<Room>> getAvailableRooms(@RequestParam String dormitory,
                                                @RequestParam(required = false) Integer floor) {
        List<Room> rooms = roomService.getAvailableRooms(dormitory, floor);
        return Result.success(rooms);
    }
    
    @PostMapping("/add")
    @SaCheckLogin
    public Result<Void> add(@RequestBody Room room) {
        roomService.save(room);
        return Result.success("添加房间成功");
    }
    
    @PutMapping("/update")
    @SaCheckLogin
    public Result<Void> update(@RequestBody Room room) {
        roomService.updateById(room);
        return Result.success("更新房间成功");
    }
    
    @DeleteMapping("/delete/{roomName}")
    @SaCheckLogin
    public Result<Void> delete(@PathVariable String roomName) {
        roomService.removeById(roomName);
        return Result.success("删除房间成功");
    }
} 